package com.glodon.zhuanli.common;

import java.util.Random;

/**
 * 随机验证码
 */
public interface UtilRandomNum {

    //验证码库数据，由此随机取单个验证码
    String[] codes = {"0" , "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9"} ;

    /**
     * 生成验证码
     * @param length 验证码长度
     * @return
     */
    static String generateVerifyCode(int length){
        Random random = new Random() ;

        String verifyCode = "" ;
        for (int i = 0; i < length ; i++) {
            int num = Math.abs(random.nextInt())%codes.length ;
            //由验证码库中取验证码
            verifyCode += codes[num] ;
        }

        return verifyCode ;
    }

}
